package com.gmp.thewizard;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PointF;
import android.util.Log;

public class Avatar {

	protected float x;
	protected float y;
	protected float r;
	protected Paint color;
	private static final String TAG = "Avatar";
	protected boolean touched;
	
	public Avatar(PointRadius point){
		this.x = point.x;
		this.y = point.y;
		this.r = point.radius;
		this.color = new Paint(Paint.ANTI_ALIAS_FLAG);
		this.color.setColor(Color.RED);
	}
	
	public Avatar(float[] spec, int color){
		this.x = spec[0];
		this.y = spec[1];
		this.r = spec[2];
		this.color = new Paint(Paint.ANTI_ALIAS_FLAG);
		this.color.setColor(color);
	}
	
	protected void draw(Canvas canvas){
		if(GameActivity.DEBUG) Log.d(TAG, "in onDraw()");
		canvas.drawCircle(this.x, this.y, this.r, this.color);
	}
	
	protected PointRadius getSpec(){
		if(GameActivity.DEBUG) Log.d(TAG, "in getSpec()");
		return new PointRadius(this.x, this.y, this.r);
	}
	
	protected void setSpec(PointF point){
		this.x = point.x;
		this.y = point.y;
		if(GameActivity.DEBUG) Log.d(TAG, "in setSpec(): x(" + this.x + ") y(" + this.y + ")");
	}
	
	protected void setSpec(PointRadius point){
		this.x = point.x;
		this.y = point.y;
		this.r = point.radius;
		if(GameActivity.DEBUG) Log.d(TAG, "in setSpec(): x(" + this.x + ") y(" + this.y + ") r(" + this.r + ")");
	}
	
	protected void setSpec(PointRadius point, int color){
		this.x = point.x;
		this.y = point.y;
		this.r = point.radius;
		this.color.setColor(color);
		if(GameActivity.DEBUG) Log.d(TAG, "in setSpec(): x(" + this.x + ") y(" + this.y + ") r(" + this.r + ") color(" + this.color + ")");
	}
	
	protected boolean handleActionDown(float xevent, float yevent){
		if(GameActivity.DEBUG) Log.d(TAG, "in handleActionDown()");
		if(GameActivity.DEBUG) Log.d(TAG, "avatar coord x=" + this.x + ", y=" + this.y);
		if((xevent >= x - r && xevent <= x + r) && (yevent >= y - r && yevent <= y + r)){
			this.touched = true;
		} else
			this.touched = false;
		if(GameActivity.DEBUG) Log.d(TAG, "is touched ? " + this.touched);
		return this.touched;
	}
	
	
	// why do I have this?
	protected boolean border(PointF screen){
		boolean hit = false;
		if(this.x < this.r || this.x > screen.x - this.r){
			hit = true;
		}
		if(this.y < this.r || this.x > screen.y - this.r){
			hit = true;
		}
		return hit;
	}
}
